﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BestLifePOS_Core.Exceptions.DataBase;
using BestLifePOS_Core.Data.Core;

namespace BestLifePOS_Core.Data.Fascade
{
    class BestlifeGetDispoBySubId : BestLifeDataAction<DataTable>
    {

        private string GvSubId;
        //  DataTable GvTable = new DataTable();

        public BestlifeGetDispoBySubId(string PSubId)
        {
            GvSubId = PSubId;
        }

        DataTable SubTable = new DataTable();

        public override DataTable Body(SqlConnection PConn)
        {
            try
            {

                #region Datatable

                SubTable.Columns.Add("Diposal Id");
                SubTable.Columns.Add("Product Id");
                SubTable.Columns.Add("Product Name");
                SubTable.Columns.Add("Description");

                #endregion

                List<string> LvList = new List<string>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.Parameters.Add(new SqlParameter("@Subcat_ID", GvSubId));//when passing parameters to the SP
                LvCommand.CommandText = "dbo.GetDispoBySubId";



                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    SubTable.Rows.Add(SubTable.NewRow());
                    //    string GVTest;

                    SubTable.Rows[SubTable.Rows.Count - 1][0] = LvReader.GetValue(0).ToString();
                    SubTable.Rows[SubTable.Rows.Count - 1][1] = LvReader.GetValue(1).ToString();
                    SubTable.Rows[SubTable.Rows.Count - 1][2] = LvReader.GetValue(2).ToString();
                    SubTable.Rows[SubTable.Rows.Count - 1][3] = LvReader.GetValue(3).ToString();
              
                
                    //    GVTest.
                    //GvTable.Rows[GvTable.Rows.Count - 1][7] = "0";



                }
                return SubTable;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
